package job.manager.db.sb;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import job.manager.db.dao.JobDAO;
import job.manager.db.dao.ProfilesDAO;
import job.manager.db.ec.AddressEB;
import job.manager.db.ec.JobEB;
import job.manager.db.ec.ProfilesEB;
import java.util.Collection;
import job.manager.db.dao.AddressDAO;

/**
 *  SessionBean is the top layer and the main access point for handling the communcation
 *  from other modules to the database.
 *  This Bean is handling all the profile requests.
 *
 */
@Stateless
public class ProfileBean implements ProfileRemote, ProfileLocal {
    @PersistenceContext
    private EntityManager em;

    public java.util.Collection<JobEB> getJobsByPid(Integer parameter) {
        JobDAO dao= new JobDAO(em);
        return dao.getJobsByPid(parameter);

    }

    public ProfilesEB getProfileInfo(Integer pk) {
        ProfilesDAO pd=new ProfilesDAO(em);
        return pd.getProfile(pk);
    }

    public Collection<AddressEB> getAddress() {
        AddressDAO dao= new AddressDAO(em);
        return dao.getAllAddresses();
    }


    public Collection<AddressEB> getAddressByPid(Integer pk) {
        AddressDAO dao= new AddressDAO(em);
        return dao.getAddressByPid(pk);
    }

    public Collection<ProfilesEB> getCustomers() {
        return new ProfilesDAO(em).getAllCustomers();
    }
    
    public Collection<ProfilesEB> getAllProfiles()
    {
        return new ProfilesDAO(em).getAllProfiles();
    }

    public ProfilesEB insertProfile(ProfilesEB p)
    {
         return new ProfilesDAO(em).insert(p);
    }

    public AddressEB insertAddress(AddressEB a)
    {
        return new AddressDAO(em).insert(a);
    }

    public int deleteProfile(ProfilesEB p) {
        ProfilesDAO dao = new ProfilesDAO(em);
        return dao.delete(p);
    }

    public int updateProfile(ProfilesEB p) {
       ProfilesDAO dao = new ProfilesDAO(em);
       return dao.update(p);
    }

    public AddressEB getAddressByPk(Integer pk) {
      AddressDAO dao = new AddressDAO(em);
      return dao.getAddress(pk);
    }

    public int updateAddress(AddressEB a) {
      AddressDAO dao = new AddressDAO(em);
      return dao.update(a);
    }

}
